package com.briup.mt.service.impl;


import com.briup.mt.bean.Counsel;
import com.briup.mt.bean.CounselExample;
import com.briup.mt.dao.CounselMapper;
import com.briup.mt.service.ICounselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * @program: app03
 * @description: 账户实现类
 * @author: charles
 * @create: 2020-12-14 15:46
 **/
@Service


public class CounselServiceImpl implements ICounselService {
    @Resource
    private CounselMapper counselMapper;

    @Override
    public List<Counsel> query(String question,String status) {
        //模板
        CounselExample example = new CounselExample();
        if (!StringUtils.isEmpty(question)){
            example.createCriteria().andQuestionLike(question);
        }
        if (!StringUtils.isEmpty(status)){
            example.createCriteria().andStatusEqualTo(status);
        }
        List<Counsel> list = counselMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Counsel counsel) {
        //如果base_User中存在id属性，表示更新；否则保存
        if (counsel.getId()==null){
            counselMapper.insert(counsel);
        }else{
            counselMapper.updateByPrimaryKey(counsel);
        }
    }



    @Override
    public void deleteById(long id) {
        counselMapper.deleteByPrimaryKey(id);
    }


}
